﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using AccessControl.Common;


namespace AccessControl.DataAcess
{
    public static class PersonGroupAccess
    {
        public static String GetGroupName(String pkPerson, int pkGroupType)
        {

            using (var cn = new SqlConnection(Util.ConnectionString))
            {
                var cmdSelect = new SqlCommand("SELECT  (tblGroupType.GroupTypeName + ' '+ tblGroup.GroupName) as x FROM tblPersonGroup inner join tblGroupType ON tblGroupType.PkGroupType=tblPersonGroup.fkGroupType inner join tblGroup ON tblPersonGroup.fkGroup=tblGroup.pkGroup WHERE tblPersonGroup.fkPerson =@fkPerson AND tblPersonGroup.fkGroupType=@fkGroupType", cn);
                cmdSelect.Parameters.AddWithValue("@fkPerson", pkPerson);
                cmdSelect.Parameters.AddWithValue("@fkGroupType", pkGroupType);
                try
                {
                    cn.Open();
                    return (string)cmdSelect.ExecuteScalar();

                }
                catch (Exception ex)
                {
                    return String.Empty;

                }
                finally
                {
                    cn.Close();
                }
            }

        }
    }
}
